package com.zhike.b2b.job.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import com.formbean.WorkForm;
import com.saas.biz.commen.Charset;
import com.saas.biz.commen.CommGetId;
import com.saas.biz.commen.CommMethodMgr;
import com.saas.sys.buffer.Buffers;
import com.saas.sys.exp.SaasApplicationException;
import com.saas.sys.log.Logger;
import com.zhike.b2b.dao.Dbtable;

public class WorkInfo
{
  Dbtable tradeQuery = new Dbtable();
  Logger log = new Logger(this);
  Buffers inBuffer;
  Buffers outBuffer;
  ArrayList queryResult = new ArrayList();
  CommMethodMgr commen = new CommMethodMgr();
  Charset charset = new Charset();

  public void setTradeQuery(Dbtable paramDbtable)
  {
    this.tradeQuery = paramDbtable;
  }

  public Dbtable getTradeQuery()
  {
    return this.tradeQuery;
  }

  public void setOutBuffer(Buffers paramBuffers)
  {
    this.outBuffer = paramBuffers;
  }

  public Buffers getOutBuffer()
  {
    return this.outBuffer;
  }

  public ArrayList getQueryResult()
  {
    return this.queryResult;
  }

  public void setQueryResult(ArrayList paramArrayList)
  {
    this.queryResult = paramArrayList;
  }

  public void addWorkInfo(Buffers paramBuffers)
  {
    this.log.LOG_INFO("进入addWorkInfo方法...");
    this.outBuffer = paramBuffers;
    this.inBuffer = paramBuffers;
    int i = -1;
    CommGetId localcommGetId = new CommGetId();
    String str = localcommGetId.getTradeId("work", "jobs_id");
    try
    {
      i = addWorkInfo(str, paramBuffers);
    }
    catch (SaasApplicationException localSaasApplicationException)
    {
      this.log.LOG_INFO(localSaasApplicationException.getMessage());
    }
    if (i != 0)
    {
      this.outBuffer.setInt("RESULT_CODE", -1);
      this.outBuffer.setString("RESULT_INFO", "业务处理失败！");
    }
    else
    {
      this.outBuffer.setInt("RESULT_CODE", 0);
      this.outBuffer.setString("RESULT_INFO", "业务处理成功！");
    }
    this.log.LOG_INFO("退出addWorkInfo方法...");
  }

  public int addWorkInfo(String paramString, Buffers paramBuffers)
    throws SaasApplicationException
  {
    try
    {
      paramBuffers.setClassName("WorkQuery");
      WorkExt localWorkExt = new WorkExt();
      localWorkExt.setParam(":VJOBS_ID", paramString);
      log.LOG_DEBUG("求职id============" + paramString);
      log.LOG_DEBUG("+====================" + (WorkForm)paramBuffers.getFormBean());
      WorkForm localWorkForm = (WorkForm)paramBuffers.getFormBean();
      log.LOG_DEBUG("姓名==============" + localWorkForm.getName());
      localWorkExt.setParam(":VNAME", localWorkForm.getName());
      log.LOG_DEBUG("姓名============" + localWorkForm.getName());
      localWorkExt.setParam(":VSEX", localWorkForm.getSex());
      localWorkExt.setParam(":VEDUCATION", localWorkForm.getEducation());
      localWorkExt.setParam(":VFEATURES", localWorkForm.getFeatures());
      localWorkExt.setParam(":VLEARNING_EC", localWorkForm.getLearning_ec());
      localWorkExt.setParam(":VEXPERIENCE", localWorkForm.getExperience());
      localWorkExt.setParam(":VPHONE", localWorkForm.getPhone());
      localWorkExt.setParam(":VMOBILE", localWorkForm.getMobile());
      localWorkExt.setParam(":VEMAIL", localWorkForm.getEmail());
      localWorkExt.setParam(":VMSN", localWorkForm.getMsn());
      localWorkExt.setParam(":VQQ", localWorkForm.getQq());
      localWorkExt.setParam(":VBIRTHPLACE", localWorkForm.getBirthplace());
      localWorkExt.setParam(":VACCOUNT", localWorkForm.getAccount());
      localWorkExt.setParam(":VINTENTION", localWorkForm.getIntention());
      log.LOG_DEBUG("求职意向============" + localWorkForm.getIntention());
      localWorkExt.setParam(":VREQUEST", localWorkForm.getRequest());
      log.LOG_DEBUG("薪资要求============" + localWorkForm.getRequest());
      localWorkExt.setParam(":VPERSONAL_ID", localWorkForm.getPersonal_id());
      localWorkExt.setParam(":VADDRESS", localWorkForm.getAddress());
      String str = "INSERT into work(jobs_id,NAME,sex,education,features,learning_ec,experience,phone,moblie,email,qq,msn,birthplace,account,intention,request,personal_id,address,add_date) values(" + paramString + "," + localWorkForm.getName() + "," + localWorkForm.getSex() + "," + localWorkForm.getEducation() + "," + localWorkForm.getFeatures() + "," + localWorkForm.getLearning_ec() + "," + localWorkForm.getExperience() + "," + localWorkForm.getPhone() + "," + localWorkForm.getMobile() + "," + localWorkForm.getQq() + "," + localWorkForm.getMsn() + "," + localWorkForm.getBirthplace() + "," + localWorkForm.getAccount() + "," + localWorkForm.getIntention() + "," + localWorkForm.getRequest() + "," + localWorkForm.getPersonal_id() + "," + localWorkForm.getAddress() + ",now())";
      log.LOG_DEBUG("添加求职信息" + str);
      this.tradeQuery.executeBy(localWorkExt.insBy("INS_WORK_ONE"));
    }
    catch (Exception localException)
    {
      this.log.LOG_INFO(localException.getMessage());
    }
    return 0;
  }

  public List getOneWorkById(String paramString)
    throws SaasApplicationException
  {
    WorkExt localWorkExt = new WorkExt();
    localWorkExt.setParam(":VJOBS_ID", paramString);
    List data = localWorkExt.selByList("SEL_WORK_BY_ID");
    if ((data != null) && (data.size() > 0))
      return data;
    return null;
  }

  public List getAllWorkInfo(int paramInt1, int paramInt2, String paramString1, String paramString2, String paramString3)
    throws SaasApplicationException
  {
    if (paramInt1 == 0)
      paramInt1 = 0;
    else
      paramInt1 = (paramInt1 - 1) * paramInt2;
    List data = null;
    WorkExt localWorkExt = new WorkExt();
    if (paramString1.equals(""))
      localWorkExt.setParam(":VNAME", "%");
    else
      localWorkExt.setParam(":VNAME", "%" + paramString1 + "%");
    if ((!"".equals(paramString2)) && ("".equals(paramString3)))
    {
      localWorkExt.setParam(":VSTART_DATE", paramString2);
      data = localWorkExt.selByList("SEL_WORK_BY_START", paramInt1, paramInt2);
    }
    else if (("".equals(paramString2)) && (!"".equals(paramString3)))
    {
      localWorkExt.setParam(":VEND_DATE", paramString3);
      data = localWorkExt.selByList("SEL_WORK_BY_END", paramInt1, paramInt2);
    }
    else if ((!"".equals(paramString2)) && (!"".equals(paramString3)))
    {
      localWorkExt.setParam(":VSTART_DATE", paramString2);
      localWorkExt.setParam(":VEND_DATE", paramString3);
      data = localWorkExt.selByList("SEL_WORK_BY_DATE", paramInt1, paramInt2);
    }
    else
    {
      data = localWorkExt.selByList("SEL_WORK_BY_NAME", paramInt1, paramInt2);
    }
    if ((data != null) && (data.size() > 0))
      return data;
    return null;
  }

  public int getAllWorkInfo(String paramString1, String paramString2, String paramString3)
    throws SaasApplicationException
  {
    List al = null;
    WorkExt localWorkExt = new WorkExt();
    if (paramString1.equals(""))
      localWorkExt.setParam(":VNAME", "%");
    else
      localWorkExt.setParam(":VNAME", "%" + paramString1 + "%");
    if ((!"".equals(paramString2)) && ("".equals(paramString3)))
    {
      localWorkExt.setParam(":VSTART_DATE", paramString2);
      al = localWorkExt.selByList("SEL_WORK_BY_START");
    }
    else if (("".equals(paramString2)) && (!"".equals(paramString3)))
    {
      localWorkExt.setParam(":VEND_DATE", paramString3);
      al = localWorkExt.selByList("SEL_WORK_BY_END");
    }
    else if ((!"".equals(paramString2)) && (!"".equals(paramString3)))
    {
      localWorkExt.setParam(":VSTART_DATE", paramString2);
      localWorkExt.setParam(":VEND_DATE", paramString3);
      al = localWorkExt.selByList("SEL_WORK_BY_DATE");
    }
    else
    {
      al = localWorkExt.selByList("SEL_WORK_BY_NAME");
    }
    if ((al != null) && (al.size() > 0))
      return al.size();
    return 0;
  }

  public List getWorkByKeyword(String paramString1, String paramString2, String paramString3)
    throws SaasApplicationException
  {
    List al = null;
    WorkExt localWorkExt = new WorkExt();
    if (paramString1.equals(""))
      localWorkExt.setParam(":VKEYWORD", "%");
    else
      localWorkExt.setParam(":VKEYWORD", "%" + paramString1 + "%");
    if (paramString3.equals(""))
      localWorkExt.setParam(":VDATE", "");
    else
      localWorkExt.setParam(":VDATE", paramString3);
    al = localWorkExt.selByList("SEL_WORK_BY_ID");
    if ((al != null) && (al.size() > 0))
      return al;
    return null;
  }

  public void delWorkById(Buffers paramBuffers)
  {
    paramBuffers.setClassName("WorkQuery");
    this.outBuffer = paramBuffers;
    this.inBuffer = paramBuffers;
    this.log.LOG_INFO("进入delWorkById方法...");
    int i = -1;
    try
    {
      String str = paramBuffers.getString("JOBS_ID");
      log.LOG_DEBUG("kkkkkkkkkkkkkk" + str);
      i = delWorkById(str);
    }
    catch (SaasApplicationException localSaasApplicationException)
    {
      this.log.LOG_INFO(localSaasApplicationException.getMessage());
    }
    if (i != 0)
    {
      this.outBuffer.setInt("RESULT_CODE", -1);
      this.outBuffer.setString("RESULT_INFO", "业务处理失败！");
    }
    else
    {
      this.outBuffer.setInt("RESULT_CODE", 0);
      this.outBuffer.setString("RESULT_INFO", "业务处理成功！");
    }
    this.log.LOG_INFO("退出delWorkById方法...");
  }

  public int delWorkById(String paramString)
    throws SaasApplicationException
  {
    WorkExt localWorkExt = new WorkExt();
    localWorkExt.setParam(":VJOBS_ID", paramString);
    this.tradeQuery.executeBy(localWorkExt.insBy("DELETE_WORK_BY_ID"));
    return 0;
  }

  public void delWorkInfo(Buffers paramBuffers)
  {
    paramBuffers.setClassName("WorkQuery");
    this.outBuffer = paramBuffers;
    this.inBuffer = paramBuffers;
    this.log.LOG_INFO("进入delWorkInfo方法...");
    int i = -1;
    try
    {
      String str = paramBuffers.getString("JOBS_ID");
      StringTokenizer localStringTokenizer = new StringTokenizer(str, "|");
      while (localStringTokenizer.hasMoreElements())
        i = delWorkById(localStringTokenizer.nextToken());
    }
    catch (SaasApplicationException localSaasApplicationException)
    {
      this.log.LOG_INFO(localSaasApplicationException.getMessage());
    }
    if (i != 0)
    {
      this.outBuffer.setInt("RESULT_CODE", -1);
      this.outBuffer.setString("RESULT_INFO", "业务处理失败！");
    }
    else
    {
      this.outBuffer.setInt("RESULT_CODE", 0);
      this.outBuffer.setString("RESULT_INFO", "业务处理成功！");
    }
    this.log.LOG_INFO("退出delWorkInfo方法...");
  }
}

